package com.xyhuo.leetcode.november;

/**
 * 第N个泰波拉契数
 * https://leetcode.cn/problems/n-th-tribonacci-number
 *
 * @time 2023、11、22
 */
public class Tribonacci {
    public int tribonacci(int n) {
        int length = n < 3 ? 3 : n;
        int[] dp = new int[length + 1];
        dp[0] = 0;
        dp[1] = 1;
        dp[2] = 1;
        for (int i = 3; i <= length; i++) {
            dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3];
        }
        return dp[n];
    }
}
